package com;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class SCM_MakeWebRepository {
	static String[] SRC_DIR = new String[] {
			"C:/develop/WALI/workspace/WALI/java/",
			"C:/develop/WALI/workspace/WALI/WEB/" };
	
	static String REP_ROOT = null;
	static String SRC_ROOT = null;
	static String SRC_TYPE = null;
	public static void main(String[] args) {
		
		try {
			SRC_TYPE = SRC_DIR[1];
			
			BufferedReader in = new BufferedReader(new FileReader("C:/repository/"+"mapWeb.txt"));
			BufferedWriter out = new BufferedWriter(new FileWriter("C:/repository/"+"makeWeb.cmd"));
			String str = null;

			while ((str = in.readLine()) != null) {
				String[] val = str.split("	");
				
				if(val.length<4){
					REP_ROOT = val[2];
				}else{
					REP_ROOT = val[2]+val[3];
				}				
				
				if(val[1].trim().length()==0){
					val[0] = val[0].replace("/", "");
					SRC_ROOT = "";
				}else{
					SRC_ROOT = "/"+val[1];
				}
				
								
				out.write(new String("rmdir "+"C:/repository/"+REP_ROOT+SRC_ROOT                             ).replace("/", "\\")+" /S/Q"+"\n");
				out.write(new String("mkdir "+"C:/repository/"+REP_ROOT+SRC_ROOT                             ).replace("/", "\\")+"\n");
				out.write(new String("xcopy "+SRC_TYPE+val[0]+val[1]+" "+"C:/repository/"+REP_ROOT+SRC_ROOT).replace("/", "\\")+" /EHKQYI"+"\n");
				
				if(val[1].trim().length()==0){
					val[0] = val[0].replace("/", "");
					SRC_ROOT = "";
					out.write(new String("xcopy "+SRC_TYPE+val[0]+"/js"+" "+"C:/repository/"+REP_ROOT+"/js").replace("/", "\\")+" /EHKQYI"+"\n");
					out.write(new String("xcopy "+SRC_TYPE+val[0]+"/res"+" "+"C:/repository/"+REP_ROOT+"/res").replace("/", "\\")+" /EHKQYI"+"\n");
					out.write(new String("copy "+SRC_TYPE+val[0]+"/*.xml"+" "+"C:/repository/"+REP_ROOT+"/").replace("/", "\\")+" /Y"+"\n");
				}else{
					SRC_ROOT = "/"+val[1];
					out.write(new String("xcopy "+SRC_TYPE+val[0]+"js"+" "+"C:/repository/"+REP_ROOT+"/js").replace("/", "\\")+" /EHKQYI"+"\n");
					out.write(new String("xcopy "+SRC_TYPE+val[0]+"res"+" "+"C:/repository/"+REP_ROOT+"/res").replace("/", "\\")+" /EHKQYI"+"\n");
					out.write(new String("copy "+SRC_TYPE+val[0]+"*.xml"+" "+"C:/repository/"+REP_ROOT+"/").replace("/", "\\")+" /Y"+"\n");
				}
				
				
				
				
				out.write(new String("dir "+"C:/repository/"+REP_ROOT+SRC_ROOT                               ).replace("/", "\\")+"\n");
				
				out.write("\n");
			}
			out.write("jar -cvfM web.jar web_*"+"\n");
			out.write("pause"+"\n");
			out.flush();
			in.close();
			out.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
